package com.yudaob2b.elong.task;

import com.alibaba.fastjson.JSONObject;
import com.yudaob2b.business.entity.po.ElongHotelDetailPO;
import com.yudaob2b.elong.entity.vo.hoteldetail.SingleHotel;
import com.yudaob2b.elong.service.HttpStaticService;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.util.concurrent.Callable;

/**
 * 查询酒店详情（静态）数据现场任务
 *
 * @author Kidd.Tan
 * @email 298023780@qq.com
 * @date 7/8/18 10:26 PM
 */
public class QueryHotelDetailTask implements Callable<ElongHotelDetailPO>, Serializable {

    private String hotelId;
    private HttpStaticService httpStaticService;

    public QueryHotelDetailTask(String hotelId, HttpStaticService httpStaticService) {
        this.hotelId = hotelId;
        this.httpStaticService = httpStaticService;
    }

    @Override
    public ElongHotelDetailPO call() throws Exception {
        ElongHotelDetailPO elongHotelDetailPO = null;
        try {
            if(StringUtils.isNotBlank(hotelId)) {
                SingleHotel singleHotel = httpStaticService.getHostDetail("cn", hotelId);
                if(singleHotel != null){
                    elongHotelDetailPO = new ElongHotelDetailPO();
                    elongHotelDetailPO.setHotel_id(singleHotel.getId());
                    elongHotelDetailPO.setDetail(JSONObject.toJSONString(singleHotel.getDetail()));
                    elongHotelDetailPO.setRoom(JSONObject.toJSONString(singleHotel.getRooms()));
                    elongHotelDetailPO.setImage(JSONObject.toJSONString(singleHotel.getImages()));
                    elongHotelDetailPO.setReview(JSONObject.toJSONString(singleHotel.getReview()));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return elongHotelDetailPO;
    }

}
